#include <iostream>
#include <string>
using namespace std;

struct Node
{
    string data;
    Node* next;
};

Node *head,*p,*r;
int n;

int main()
{

    head = new Node;
    r = head;

    
    while(1)
    {
    cout<<"1.输入新的字符串"<<endl;
    cout<<"2.显示目前所有的字符串"<<endl;
    cout<<"3.对目前所有的字符串排序并显示"<<endl;
    cout<<"4.退出程序"<<endl;
    int x;
    cin>>x;
    if(x==1)
    {
       
       
       
        string a;
        cin>>a;
        p = new Node;
        p->data = a;
        p->next = NULL;

        r->next = p;
        r=p;
       }

    if(x==2)
    {
    	
        Node*q;
        q=head->next;
        while(q->next!=NULL)
        {
            cout<<q->data<<endl;
            q=q->next;


        }
        
        
        cout<<q->data<<endl;



    }

       
   if(x==3)
    {
            Node*j; 
            j=head->next;
            int o=0;
            Node*r = j;
            while(r->next!=NULL)
            {
                o++;
                r=r->next;
            }
            o=o+1;

    for(int i=0;i<o-1;i++)
    {
            while(j->next!=NULL)
            {
            Node*k = j;
            Node*l= j->next;
            string c = j->data;
            string d = j->next->data;       
            if(c>d)
            {
                string m;
                m=j->data;
                j->data = j->next->data;
                j->next->data = m;
            }
                j=j->next;

            }

            
    }

    Node*v;
        v=head->next;
        while(v->next!=NULL)
        {
            cout<<v->data<<endl;
            v=v->next;


        }     
        cout<<v->data<<endl;
    }


    if(x==4)
    {
        break;
    }

    }



    system("pause");

}

